<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:dssp="http://schemas.microsoft.com/xw/2004/10/dssp.html"
    xmlns:tpa81="http://www.robot-electronics.co.uk/2006/10/tpa81hardware.html" 
    >

  <xsl:import href="/resources/dss/Microsoft.Dss.Runtime.Home.MasterPage.xslt" />

  <xsl:template match="/">
    <xsl:comment>
      <!-- Service Header Info -->
    </xsl:comment>
    <xsl:variable name="title">
      TPA81 Hardware Service
    </xsl:variable>
    <xsl:variable name="serviceName">
      TPA81 Hardware Service
    </xsl:variable>
    <xsl:variable name="description">
      The TPA81 can measure the temperature of 8 adjacent points simultaneously. The TPA81
      can also control a servo to pan the module and build up a thermal image. The TPA81
      can detect a candle flame at a range 2 metres (6ft) and is unaffected by ambient
      light!
    </xsl:variable>

    <xsl:call-template name="MasterPage">
      <xsl:with-param name="serviceName" select="$serviceName" />
      <xsl:with-param name="description" select="$description" />
      <!-- If title is not provided, serviceName will be used instead. -->
      <xsl:with-param name="title">
        <xsl:value-of select="$serviceName" />
        <xsl:if test="$title != ''">
          <xsl:text> - </xsl:text>
          <xsl:value-of select="$title" />
        </xsl:if>
      </xsl:with-param>
      <!-- Possible values for navigation are: 'Open', 'Closed', and 'None'
           'Open' is the default value. -->
      <xsl:with-param name="navigation" select="'Open'" />
      <!-- The contents of head param will be placed just before the </head> tag in html. -->
      <xsl:with-param name="head">
        <link rel="stylesheet" type="text/css" href="/resources/I2CHardware/Devantech.Services.I2C.Hardware.resources.DevantechI2CHardware.Stylesheet.css" />

        <style type="text/css">
          /* Service-specific stylesheet goes here */
          td.Pixel {width:30px; height: 30px; vertical-align: top; color: #003399; font-size: 11px;  font-weight: bold; }

        </style>
        <script language="javascript" type="text/javascript">
          <![CDATA[<!--

/* Service-specific script goes here */

dssRuntime.init = function()
{
  // Add page initialization code here.
  // This function is attached to the window.onload event.
  // Do not override window.onload.
}

//-->     ]]>
        </script>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- Match service state's document element. -->
	<xsl:template match="/tpa81:TPA81State">
				<div class="RightColumn">
					<span class="SubTitle">
						<xsl:value-of select="count(tpa81:Modules/*)" /> module
						<xsl:if test="count(tpa81:Modules/*) &gt; 1">s</xsl:if>
						found
					</span>
				</div>
				<br clear="all"/>
				<xsl:for-each select="tpa81:Modules/*">
					<div class="Module">
						<span class="ModuleName"><form method="POST" id="NewI2CAddressForm">
							TPA81 Revision <xsl:value-of select="tpa81:SoftwareRevision"/> found at I2C Address
							<xsl:choose>
								<xsl:when test="count(//tpa81:Modules/*) = 1">
									
									<input id="NewI2CAddress"  name="NewI2CAddress"
									class="Editable" maxlength="3" onblur="this.className='Editable';document.getElementById(this.id + 'Form').submit();"
									onfocus="this.className='EditableActive'" title="Click to Edit the I2C Address. NB: Make sure panning and polling are off!">
										<xsl:attribute name="value">
											<xsl:value-of select="tpa81:I2CAddress"/>
										</xsl:attribute>
									</input>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="tpa81:I2CAddress"/>
								</xsl:otherwise>
							</xsl:choose></form>
						</span>
						<br />
						<span class="SmallText">
							Last contact: <xsl:value-of select="tpa81:LastContact"/>
						</span>
						<br />
						<br />
						<table class="layout">
							<tr>
								<td>
									<table class="Pixels">
										<tr>
											<th colspan="8">
												<span class="SmallTextRight">Ambient: <xsl:value-of select="tpa81:AmbientTemperature"/>C
												
											</span>
												Thermopile Array
											</th>
										</tr>
										<tr>
											<xsl:for-each select="tpa81:Pixels/*">
												<td class="Pixel">
													<xsl:variable name="ambDif" select=". - ../../tpa81:AmbientTemperature" />
													<xsl:attribute name="style">
														<xsl:text>background-color: rgb(</xsl:text>
														<xsl:choose>
															<xsl:when test="$ambDif &gt; 0">
																<xsl:value-of select="100 + ($ambDif*3)" />
																<xsl:text>,100,100</xsl:text>
															</xsl:when>
															<xsl:otherwise>
																<xsl:text>100,100,</xsl:text>
																<xsl:value-of select="100 + ($ambDif*3)" />
															</xsl:otherwise>
														</xsl:choose>
														<xsl:text>)</xsl:text>
													</xsl:attribute>
												</td>
											</xsl:for-each>
										</tr>
										<tr>
											<xsl:for-each select="tpa81:Pixels/*">
												<td class="Pixel">
													<xsl:value-of select="." />
													C
												</td>
											</xsl:for-each>
										</tr>
									</table>
								</td>
								<td width="20"></td>
								<td>
									<table class="Config">
										<tr>
											<th colspan="2">Servo</th>
										</tr>
										<tr>
											<td class="SmallText">Position</td>
											<td class="SmallText">
												<form method="POST"  id="ServoPositionForm">
													<input type="hidden" name="I2CAddress">
														<xsl:attribute name="value">
															<xsl:value-of select="tpa81:I2CAddress"/>
														</xsl:attribute>
													</input>
													<input id="ServoPosition"
													 class="Editable"
													 maxlength="2"
													 name="ServoPosition"
													 onblur="this.className='Editable';document.getElementById(this.id + 'Form').submit();"
													 onfocus="this.className='EditableActive'" title="Click to change the servo position"
													 type="text" >
														<xsl:attribute name="value">
															<xsl:value-of select="tpa81:ServoPosition"/>
														</xsl:attribute>
													</input>
														
												</form>
											</td>
										</tr>
										<tr>
											<td class="SmallText">
												Range
											</td>
											<td>
												<form method="POST"  id="ServoRangeForm">
													<input type="hidden" name="I2CAddress">
														<xsl:attribute name="value">
															<xsl:value-of select="tpa81:I2CAddress"/>
														</xsl:attribute>
													</input>
													<input id="ServoRange" class="Editable"
													 name="ServoRange" 
													 onblur="this.className='Editable';document.getElementById(this.id + 'Form').submit();"
													 onfocus="this.className='EditableActive'" title="Click to change the servo range"
													 type="text" maxlength="3">
														<xsl:attribute name="value">
															<xsl:value-of select="tpa81:ServoRange"/>
														</xsl:attribute>
													</input>
												</form>
											</td>
										</tr>
									</table>
								</td>
								<td width="20">
								</td>
								<td>
									<table class="Config">
										<tr>
											<th colspan="2">
												Config
											</th>
										</tr>
										<tr>
											<td class="SmallText">
												Auto-Poll
											</td>
											<td class="SmallText">
												<form method="POST"  id="EnablePollingForm">
													<input type="hidden" name="EnablePollingChange" value="true"/>
													<input type="hidden" name="I2CAddress">
														<xsl:attribute name="value">
															<xsl:value-of select="tpa81:I2CAddress"/>
														</xsl:attribute>
													</input>
													<input id="EnablePolling" name="EnablePolling" onclick="document.getElementById(this.id + 'Form').submit();"
														title="Click to enable Polling of the sensor" type="checkbox">
														<xsl:if test="//tpa81:Configs/tpa81:Config[position()]/tpa81:EnablePolling = 'true'">
															<xsl:attribute name="checked">CHECKED</xsl:attribute>
															<xsl:attribute name="value">on</xsl:attribute>
														</xsl:if>
													</input>
												</form>
											</td>
										</tr>
										<tr>
											<td class="SmallText">
												Auto-Pan
											</td>
											<td class="SmallText">
												<form method="POST"  id="EnablePanningForm">
													<input type="hidden" name="EnablePanningChange" value="true"/>
													<input type="hidden" name="I2CAddress">
														<xsl:attribute name="value">
															<xsl:value-of select="tpa81:I2CAddress"/>
														</xsl:attribute>
													</input>
													<input id="EnablePanning" name="EnablePanning" onclick="document.getElementById(this.id + 'Form').submit();"
														title="Click to enable Panning of the servo" type="checkbox" >
														<xsl:if test="//tpa81:Configs/tpa81:Config[position()]/tpa81:EnablePanning = 'true'">
															<xsl:attribute name="checked">CHECKED</xsl:attribute>
															<xsl:attribute name="value">on</xsl:attribute>
														</xsl:if>
													</input>
												</form>
											</td>
										</tr>
										<tr>
											<td class="SmallText">
												Delay
											</td>
											<td>
												<form method="POST"  id="PollDelayForm">
													<input type="hidden" name="I2CAddress">
														<xsl:attribute name="value">
															<xsl:value-of select="tpa81:I2CAddress"/>
														</xsl:attribute>
													</input>
													<input id="PollDelay" class="Editable" maxlength="5" name="PollDelay" onblur="this.className='Editable';document.getElementById(this.id + 'Form').submit();"
														onfocus="this.className='EditableActive'" title="Click to change the Delay between panning or polling"
														type="text" >
														<xsl:attribute name="value">
															<xsl:value-of select="//tpa81:Configs/tpa81:Config[position()]/tpa81:PollDelay" />
														</xsl:attribute>
													</input>
												</form>
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</div>
				</xsl:for-each>
				<div class="hr"></div>
				<div class="RightColumn">
					<a class="LinkSmall" href="http://www.robot-electronics.co.uk/htm/tpa81tech.htm">View Devantech documentation</a>
				</div>
        Configuration at: /store/Devantech.Services.TPA81.Hardware.xml
	</xsl:template>
</xsl:stylesheet>
